package com.jml.排序;

public class 递归 {

	public static void main(String[] args) {
 		int arr[] ={1,2,3,4,17,5,12,7,9};
		int max = getMax(arr,0,arr.length-1);
		System.out.println(max);
	}
	//左边最大，右边最大，取最大
	private static int getMax(int[] arr, int l, int r) {
		if(r-l == 1){
			return arr[l]>arr[r]?arr[l]:arr[r];
		}
		if(l==r){
			return arr[l];
		}
		int mid = (l+r)/2;
		int maxl = getMax(arr, l, mid);
		int maxr = getMax(arr, mid + 1, r);
		return maxl>maxr?maxl:maxr;
	}

}
